<!DOCTYPE html>
<title>Test media element's "played" attribute.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="video-played.js"></script>
<video></video>
<script>
var video;
async_test(function(t) {
    var expectedStartTimes = [];
    var expectedEndTimes = [];
    video = document.querySelector("video");

    video.oncanplay = t.step_func(function() {
        video.oncanplay = null;
        testRanges(expectedStartTimes, expectedEndTimes);
        // Test playing when there are no ranges.
        timeRangeCount = currentTimeRange = 0;
        startPlayingInNewRange(t, expectedStartTimes);
    });
    waitForPauseAndContinue(t, resetToAVideoSource, false, expectedStartTimes, expectedEndTimes);

    function resetToAVideoSource() {
        // Test to reset to non empty video source.
        timeRangeCount = currentTimeRange = 0;
        expectedStartTimes = [];
        expectedEndTimes = [];
        video.src = "content/test.ogv";
        video.oncanplay = t.step_func(jumpAndPlayFwd);
    }

    function jumpAndPlayFwd() {
        video.oncanplay = null;
        testRanges(expectedStartTimes, expectedEndTimes);
        // Test jumping forward into a new range and play.
        video.currentTime = (video.duration - 0.5).toFixed(2);
        currentTimeRange = 1;
        startPlayingInNewRange(t, expectedStartTimes);
        waitForPauseAndContinue(t, resetToAnEmptyVideoSource, false, expectedStartTimes, expectedEndTimes);
    }

    function resetToAnEmptyVideoSource() {
        // Test to reset to an empty video source.
        timeRangeCount = currentTimeRange = 0;
        expectedStartTimes = [];
        expectedEndTimes = [];
        video.src = "";
        video.onloadstart = t.step_func_done(testRanges(expectedStartTimes, expectedEndTimes));
    }

    video.src = "content/test.ogv";
});
</script>